import DataBase from '../../Server/Data/DataBase';
import GameUtil from '../../Fantasy/Util/GameUtil';
import ServerCenter from '../../Server/ServerCenter';
import SoundUtil from '../../Fantasy/Util/SoundUtil';
import JsbUtil from '../../Fantasy/Util/JsbUtil';


const {ccclass, property} = cc._decorator;

@ccclass
export default class MainScene extends cc.Component {

    @property(cc.Node)
    GiftLayer: cc.Node = null;
    @property(cc.Node)
    RankLayer: cc.Node = null;
    @property(cc.Node)
    GloryLayer: cc.Node = null;
    @property(cc.Node)
    RushLayer: cc.Node = null;
    @property(cc.Node)
    PKLayer: cc.Node = null;
    @property(cc.Node)
    GiftRule: cc.Node = null;
    @property(cc.Node)
    gameRule: cc.Node = null;

    @property(cc.Node)
    bookInfo: cc.Node = null;
    @property(cc.Label)
    myExp : cc.Label = null;
    @property(cc.Label)
    myRank : cc.Label = null;
    @property(cc.Label)
    myPKwin : cc.Label = null;
    @property(cc.Label)
    myLoginDay : cc.Label = null;
    @property(cc.Label)
    currLevel : cc.Label = null;
    @property(cc.Label)
    maxLevel : cc.Label = null;

    @property(cc.Label)
    bookName : cc.Label = null;



    onLoad () {
        JsbUtil.init();
        SoundUtil.init();
        GameUtil.sceneName = "MainScene";
        let bookId = 6;
        GameUtil.updateDay();
        GameUtil.updateDate();
        this.updateMyInfo(bookId);
        this.GiftLayer.active = false;
        this.RankLayer.active = false;
        this.GloryLayer.active = false;
        this.RushLayer.active = false;
        this.PKLayer.active = false;
        this.updateBookName();
        PlayMusic("music/bgMusic",true);
        JsbUtil.listenAndroidBack();
    }
    updateBookName(){
        this.bookName.getComponent(cc.Label).string = ServerCenter.getBookName(GameUtil.openBookId);
    }

    updateMyInfo(bookId){
        this.myExp.string = ServerCenter.getUserExp() + '';
        this.myRank.string = ServerCenter.getUserRank() + '';
        this.myPKwin.string = ServerCenter.getUserVictory() + '场';
        this.myLoginDay.string = ServerCenter.getUserContinueLogin() + '天';
        this.currLevel.string = '第' + ServerCenter.getCurrLevel(bookId) + '关';
        this.maxLevel.string = '共' + ServerCenter.getMaxLevel(bookId) + '关';
    }

    btnCallback(target,data){
        SoundUtil.playEffect("music/click");
        if (data == 'Gift'){
            this.GiftLayer.active = true;
        }else if(data == 'GiftRule'){
            this.GiftRule.active = true;
        }else if(data == "closeGR"){
            this.GiftRule.active = false;
        }else if(data == 'gameRule'){
            this.gameRule.active = true;
        }
        else if (data == 'Rank'){
            this.RankLayer.active = true;
        }
        else if (data == 'Glory'){
            this.GloryLayer.active = true;
        }
        else if (data == 'Rush'){
            this.RushLayer.active = true;
            JsbUtil.showCp();
        }
        else if (data == 'PK'){
            this.PKLayer.active = true;
        }else if (data == 'selectBook'){
            this.bookInfo.active = true;

        }else if(data == "closeBookInfo"){
            this.bookInfo.active = false;
        }else if(data == "yinsi"){
            JsbUtil.yszc()

        }
    }


    setBook(target,data){
        SoundUtil.playEffect("music/click");
        GameUtil.setOpenBookId(parseInt(data));
        this.bookInfo.active = false;
        this.updateBookName();
    }


}
